/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gskorupa.univermon.auth;

// TODO: use storage implementation to store clients

import java.util.HashMap;

/**
 *
 * @author greg
 */
public class RegisteredClients {
    
    public static int OK = 0;
    public static int UNKNOWN_DEVICE = -2;
    public static int UNKNOWN_CLIENT = -1;
    public static int ALREADY_REGISTERED = -3;
    
    private static volatile RegisteredClients instance = new RegisteredClients();
    HashMap<String,Client> clientList;
    
    private RegisteredClients() {
        clientList=new HashMap();
        Client c=new Client();
        
        // secretkey@admin@mydomain
        c.setUid("30de7e353d0573f64e1288bbe499522c");
        c.addDevice("testdevice");
        c.setConfirmed(true);
        clientList.put(c.getUid(),c);
    }
 
    public static RegisteredClients getInstance() {
        return instance;
    }
    
    public int add(Client client){
        clientList.put(client.getUid(),client);
        return RegisteredClients.OK;
    }
    
    public int isRegistered(String uid, String device){
        //System.out.println(uid+"@"+device);
        Client c=clientList.get(uid);
        if(c!=null){
            if(c.isDevice(device)){
                return OK;
            }else{
                return UNKNOWN_DEVICE;
            }
        }
        return UNKNOWN_CLIENT;
    }
    
    public Client get(String uid){
        //System.out.println(uid+"@"+device);
        Client c=clientList.get(uid);
        return c;
    }
}
